import allure

from data.temporary_value import A
from utils.LogUtil import my_log

a = A()


def read_temporary(*args):
    # 读取临时参数 传入多个key,返回字典
    tem_dict = {}
    for ar in args:
        if hasattr(a, ar):
            tem_dict[ar] = getattr(a, ar)
        else:
            my_log(__file__).debug("{}未找到对应的临时参数".format(ar))
            raise
    my_log(__file__).debug("返回临时参数{}".format(tem_dict))
    with allure.step('读取随机临时参数-{}'.format(tem_dict)):
        return tem_dict


@allure.step('利用反射写入临时参数')
def write_temporary(tem_dict):
    # 写入临时参数 传字典,无返回
    for key in list(tem_dict.keys()):
        setattr(a, key, tem_dict[key])
    my_log(__file__).debug("写入临时参数{}".format(tem_dict))


if __name__ == '__main__':
    di = {
        'Authorization': 'Basic YXBwY2xpZW50OmFwcGNsaWVudDEyMzQ=',
        'Authorization1': 'Basic YXBwY2xpZW50OmFwcGNsaWVudDEyMzQ=111111'
    }
    write_temporary(di)
    print(read_temporary('Authorization', 'Authorization1'))
